// 图片切换swiper
$(function () {

    // let cultrueSwiperOpts = {
    //     observer: true,
    //     observeSlideChildren: true,
    //     observeParents: true,  //这三个可以去文档看下介绍，主要就是异步情况会重新加载swiper。
    //     loop: true, //开启环路
    //     //spaceBetween:40,
    //     speed: 20000, //每个轮播图过渡的时间
    //     loopedSlides: 2, //比你页面显示的数量大于2就好
    //     updateOnWindowResize: true,  //分辨率改变时，防止样式错乱加上！
    //     noSwiping: true,
    // }

    // var cultureBgSwiper1 = new Swiper('.culture-bg-swiper1', {
    //     ...cultrueSwiperOpts,
    //     autoplay: {
    //         delay: 0,  //每循环一圈，间隔时间，无缝轮询，则为0
    //         ///reverseDirection: false,
    //     }
    // });
    // var cultureBgSwiper2 = new Swiper('.culture-bg-swiper2', {
    //     ...cultrueSwiperOpts,
    //     autoplay: {
    //         delay: 0,  //每循环一圈，间隔时间，无缝轮询，则为0
    //         reverseDirection: true,
    //     }

    // });
    // var cultureBgSwiper3 = new Swiper('.culture-bg-swiper3', {
    //     ...cultrueSwiperOpts,
    //     autoplay: {
    //         delay: 0,  //每循环一圈，间隔时间，无缝轮询，则为0
    //         //reverseDirection: false,
    //     }
    // });

    var cultureBgAnimeR = anime({
        targets: '.anime-direction-r .scrolling-item',
        translateX: [0, '100%'],
        easing: 'linear',
        loop: true,
        duration: 20000,
        autoplay: true
    });
    var cultureBgAnimeL = anime({
        targets: '.anime-direction-l .scrolling-item',
        translateX: ['100%', '0'],
        easing: 'linear',
        loop: true,
        duration: 20000,
        autoplay: true
    });

    var oncePlayVal = 0;
    var historySwiper = new Swiper('.history-swiper', {
        slidesPerView: 3,
        //slidesPerView: "auto",
        slidesPerGroup: 3,
        spaceBetween: 80,
        speed: 800,
        init: false,
        //centeredSlides: true,
        //loop: true,
        autoplay: {
            delay: 4000,
            stopOnLastSlide: false,
            disableOnInteraction: false,
        },
        navigation: {
            nextEl: '.J-history-next',
            prevEl: '.J-history-prev',
        },
        pagination: {
            el: '.history-pagination',
            type: 'fraction',
        },
        breakpoints: {
            1440: { //当屏幕宽度小于等于1440
                spaceBetween: 50,
            },
        },
        on: {
            init: function () {
                //$('.news-title-box .item').eq(this.realIndex).addClass('active')
            },
            slideChangeTransitionEnd: function () {
                if (this.isEnd) {
                    this.autoplay.stop();
                }
            },
        }
    });
    var joinSwiper = new Swiper('.join-swiper', {
        slidesPerView: 3,
        spaceBetween: 0,
        speed:800,
        centeredSlides: true,
        init: false,
        loop: true
    });

    // var joinSwiper = new Swiper('.join-swiper', {
    //     watchSlidesProgress: true,
    //     slidesPerView: 'auto',
    //     slidesPerView: 3,
    //     //spaceBetween: 0,
    //     //speed: 800,
    //     centeredSlides: true,
    //     init: false,
    //     loop: true,
    //     on: {
    //         progress: function (progress) {
    //             for (i = 0; i < this.slides.length; i++) {
    //                 var slide = this.slides.eq(i);
    //                 var slideProgress = this.slides[i].progress;
    //                 modify = 1;
    //                 if (Math.abs(slideProgress) > 1) {
    //                     modify = (Math.abs(slideProgress) - 1) * 0.3 + 1;
    //                 }
    //                 translate = slideProgress * modify * 260 + 'px';
    //                 scale = 1 - Math.abs(slideProgress) / 10;
    //                 zIndex = 999 - Math.abs(Math.round(10 * slideProgress));
    //                 slide.transform('translateX(' + translate + ') scale(' + scale + ')');
    //                 slide.css('zIndex', zIndex);
    //                 slide.css('opacity', 1);
    //                 if (Math.abs(slideProgress) > 3) { 
    //                     slide.css('opacity', 0);
    //                 }
    //             }
    //         },
    //         setTransition: function (transition) {
    //             for (var i = 0; i < this.slides.length; i++) { 
    //                 var slide = this.slides.eq(i)
    //                 slide.transition(transition);
    //             }

    //         }
    //     }
    // });

    $('.join-swiper').on('click', '.swiper-slide-next', function () {
        //console.log('点击切换到当前卡片')
        joinSwiper.slideNext()
    })
    $('.join-swiper').on('click', '.swiper-slide-prev', function () {
        //console.log('点击切换到当前卡片')
        joinSwiper.slidePrev()
    })


    if (!isMobile) {
        //console.log("PC端才初始化swiper")
        historySwiper.init() // PC端才初始化 history swiper
        historySwiper.autoplay.stop();
        joinSwiper.init() // PC端才初始化 join swiper
    }

    let honourSwiper = new Swiper('.honour-swiper', {
        effect: 'slide',
        speed: 500,
        loop: true,
        // autoplay: {
        //     delay: 4000,
        //     disableOnInteraction: false,
        // },
        navigation: {
            nextEl: '.J-honour-next',
            prevEl: '.J-honour-prev',
        },
        pagination: {
            el: '.honour-pagination',
            type: 'fraction',
        },
        on: {
            init: function () {
                //$('.news-title-box .item').eq(this.realIndex).addClass('active')
            },
            slideChangeTransitionStart: function () {
                //$('.news-title-box .item').eq(this.realIndex).addClass('active').siblings().removeClass('active')
            },
            slideChangeTransitionEnd: function () {

            },
        }
    })

    // 发展历史自动播放触发 && 数字跳动动画
    var historyTop = $('.history-swiper-box').offset().top;
    var numItemTop = $('.about-cont3').offset().top;
    console.log("historyTop:" + numItemTop)
    //console.log("numItemTop:"+numItemTop)
    var k = $(window).height() - 240;
    //console.log("WINH:"+k)
    var animeflag = true;
    $(window).scroll(function () {

        var scrollTop = $(this).scrollTop();

        //console.log('scrollTop:'+scrollTop)

        // 触发发展历史自动滚动
        if (scrollTop > historyTop - $(window).height()) {
            if (!isMobile && oncePlayVal == '0') {
                historySwiper.autoplay.start();
                oncePlayVal = 1
            }
        }

        if (scrollTop > numItemTop - k) {
            if (animeflag) {
                console.log("ok");
                $('.honour-list li .anime-num').each(function (index) {
                    var self = $(this);
                    //console.log(self)
                    var myObject = {
                        prop: 0
                    }
                    var targetValue = self.data("value")
                    anime({
                        targets: myObject,
                        prop: targetValue,
                        easing: 'linear',
                        round: 1,
                        update: function () {
                            self.html(myObject.prop)
                        }
                    });
                })
                animeflag = false;
            }
        } else {
            if (!animeflag) {
                //$('.honour-list li .anime-num').html('0<i>项</i>')
                animeflag = true;
            }
        }

    })

})